home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
cpphtp2
/
code.jar
/
code
/
ch21
/
fig21_06.txt
< prev
next >
Wrap
Text File
|
1998-02-27
|
850b
|
37 lines
1 // Fig. 21.6: fig21_06.cpp
2 // Demonstrating RTTI capability typeid.
3 #include <iostream.h>
4 #include <typeinfo.h>
5
6 template < typename T >
7 T maximum( T value1, T value2, T value3 )
8 {
9 T max = value1;
10
11 if ( value2 > max )
12 max = value2;
13
14 if ( value3 > max )
15 max = value3;
16
17 // get the name of the type (i.e., int or double)
18 const char *dataType = typeid( T ).name();
19
20 cout << dataType << "s were compared.\nLargest "
21 << dataType << " is ";
22
23 return max;
24 }
25
26 int main()
27 {
28 int a = 8, b = 88, c = 22;
29 double d = 95.96, e = 78.59, f = 83.89;
30
31 cout << maximum( a, b, c ) << "\n";
32 cout << maximum( d, e, f ) << endl;
33
34 return 0;
35 }
}